package com.study.scala.lesson01

object yanghui00 {
  def yanghui(c: Int, r: Int): Int = {
    var o = c+1
    var p = r+1
    val count = (p*(p+1))/2
    var tmp = new Array[Int](count)
    for( y <- 1 to p) {
      for(x <- 1 to p ) {
        if (x == 1 || y == 1 || y == x) {
          var num = (y * (y + 1)) / 2
          tmp(num - y + x - 1) = 1
        }else {
          var x1 = x - 1
          var x2 = x
          var y1 = y - 1
          var num1 = (y * (y - 1)) / 2
          var num = (y * (y + 1)) / 2
          tmp(num - y + x-1) = tmp(num1 - y1 + x2-1) + tmp(num1 - y1 + x1-1)
        }
      }
    }
    tmp(count-p+o-1)
  }
  def main(args: Array[String]): Unit = {
    var n:Int = 6
    for (row <- 0 to n) {
      for (col <- 0 to row)
      print(yanghui(col, row) + " ")
      println()
    } 
  }
}